import { defineStore } from "pinia";
import { Names } from "../../store-namespace";
import { _get, _post, _put, _delete, http } from "@/utils/axios";
import { EquipMCarbon } from "@/api/backend/index";

export const useCarbon = defineStore(Names.carbon, {
  state: () => {
    return {
      loading: false,
      item: {
        timeNum: 0, //累计运行时长
        replaceNum: 0, //更换滤芯次数
        replaceTime: "", //最新更换滤芯时间
        criticalValue: 0, //活性炭压力临界值
        createBy: null,
        createTime: "",
        createUser: null,
        ecode: "",
        eid: 0,
        id: 0,
        life: null,
        lifeValue: 0,
        params: {},
        pressureValue: 0,
        remark: null,
        searchValue: null,
        state: null,
        updateBy: null,
        updateTime: null,
        usernum: 0, //用量
        repalcenum: 0, //额定更换量
        type: null, //类型
      },
      option: {
        series: [
          {
            type: "gauge",
            min: 0,
            max: 500,
            progress: {
              show: true,
              width: 18,
            },
            axisLine: {
              lineStyle: {
                width: 18,
              },
            },
            axisTick: {
              show: false,
            },
            splitLine: {
              length: 15,
              lineStyle: {
                width: 2,
                color: "#999",
              },
            },
            axisLabel: {
              distance: 25,
              color: "#999",
              fontSize: 20,
            },
            anchor: {
              show: true,
              showAbove: true,
              size: 25,
              itemStyle: {
                borderWidth: 10,
              },
            },
            title: {
              show: false,
            },
            detail: {
              valueAnimation: true,
              fontSize: 80,
              offsetCenter: [0, "70%"],
            },
            data: [
              {
                value: 70,
              },
            ],
          },
        ],
      },
      gatewaycode: "",
    };
  },
  getters: {},
  actions: {
    //过滤树功能
    getListByRegions(data: any) {
      return new Promise((resolve, reject) => {
        _get(EquipMCarbon + "/listByregions", data, "", "").then((res) => {
          console.log("过滤树功能", res);
          resolve(res);
        });
      });
    },
    //获取活性炭的数据
    getCarbonInfo(data: any) {
      return new Promise((resolve, reject) => {
        _get(EquipMCarbon + "/list", data, "", "").then((res) => {
          console.log("获取活性炭的数据", res);
          resolve(res);
        });
      });
    },
    //活性炭更新初始值
    updateCarbonData(data: any) {
      console.log("活性炭更新初始值", data);
      return new Promise((resolve, reject) => {
        _put("/system/estate", data, "json", "")
          .then((res: any) => {
            resolve(res);
          })
          .catch((err: any) => {
            reject(err);
          });
      });
    },
    //获取活性炭单个数据
    getCarbonItem(data: any) {
      return new Promise((resolve, reject) => {
        _get("/system/estate", data, "json", "")
          .then((res: any) => {
            resolve(res);
          })
          .catch((err: any) => {
            reject(err);
          });
      });
    },
    //获取活性炭id的单个数据
    getCarbonItemById(id: any) {
      return new Promise((resolve, reject) => {
        _get("/system/estate/list", { eid: id }, "json", "")
          .then((res: any) => {
            console.log("获取活性炭id的单个数据", res);

            resolve(res);
          })
          .catch((err: any) => {
            reject(err);
          });
      });
    },
  },
});
